<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="60px">
      <el-form-item label="申请人姓名" prop="xm" label-width="100px">
        <el-input v-model="queryParams.xm" placeholder="请输入申请人姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请人身份证" prop="sfzhm" label-width="100px">
        <el-input v-model="queryParams.sfzhm" placeholder="请输入申请人身份证号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="申请人学号" prop="xh" label-width="100px">
        <el-input v-model="queryParams.xh" placeholder="请输入申请人学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核意见" label-width="100px" prop="yj" class="query">
        <el-select @change="handleQuery" v-model="queryParams.yj" clearable placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学院" prop="collegeId">
        <el-select v-model="queryParams.collegeId" placeholder="请选择学院" filterable clearable>
          <el-option v-for="item in deptNameList" :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学年" prop="applyYear" label-width="100px">
        <el-select @change="handleQuery" v-model="queryParams.applyYear" clearable placeholder="请选择">
          <el-option
            v-for="item in yearOptions"
            :key="item.stuYearName"
            :label="item.stuYearName"
            :value="item.stuYearName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出全部</el-button>
      </el-col>
      <!--           <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['system:apply:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="#" align="center" prop="id" />
      <el-table-column label="学年" align="center" prop="applyYear" />
      <!-- <el-table-column label="1：提交，2：班级" align="center" prop="step" /> -->
      <el-table-column label="学院" align="center" prop="xy" />
      <el-table-column label="申请人姓名" align="center" prop="xm" />
      <el-table-column label="性别" align="center" prop="xb" />
      <el-table-column label="民族" align="center" prop="mz" />
      <el-table-column label="身份证号码" align="center" prop="sfzhm" />
      <el-table-column label="学号" align="center" prop="xh" />
      <el-table-column label="班级" align="center" prop="bj" />
      <el-table-column label="出生年月" align="center" prop="csny" />
      <el-table-column label="辅导员审核意见" align="center" prop="bjpyyj">
        <template slot-scope="scope">
          <div v-if="scope.row.bjpyyj">
            <div v-if="scope.row.bjpyyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.bjpyyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.bjpyyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.bjpyyj == '4'">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="二级学院领导审核意见" align="center" prop="ejxyldqmyj">
        <template slot-scope="scope">
          <div v-if="scope.row.ejxyldqmyj">
            <div v-if="scope.row.ejxyldqmyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.ejxyldqmyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.ejxyldqmyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.ejxyldqmyj == '4'">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="学校审核意见" align="center" prop="xsqmyj">
        <template slot-scope="scope">
          <div v-if="scope.row.xsqmyj">
            <div v-if="scope.row.xsqmyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.xsqmyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.xsqmyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.xsqmyj == '4'" style="color: #ff5500">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-if="scope.row.step == 1" v-hasPermi="['system:apply:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-if="scope.row.step == 2" v-hasPermi="['system:apply:edit']">班级审核</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-if="scope.row.step == 3" v-hasPermi="['system:apply:edit']">二级学院审核</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleRevoke(scope.row)" v-if="scope.row.step == 5">撤回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改困难认定对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="1：提交，2：班级" prop="step">
          <el-input v-model="form.step" placeholder="请输入1：提交，2：班级" />
        </el-form-item>
        <el-form-item label="申请人姓名" prop="xm">
          <el-input v-model="form.xm" placeholder="请输入申请人姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="xb">
          <el-input v-model="form.xb" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="民族" prop="mz">
          <el-input v-model="form.mz" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="sfzhm">
          <el-input v-model="form.sfzhm" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="学号" prop="xh">
          <el-input v-model="form.xh" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="出生年月" prop="csny">
          <el-input v-model="form.csny" placeholder="请输入出生年月" />
        </el-form-item>
        <el-form-item label="困难类型1" prop="knlx">
          <el-input v-model="form.knlx" placeholder="请输入困难类型1" />
        </el-form-item>
        <el-form-item label="困难类型2" prop="knlx2">
          <el-input v-model="form.knlx2" placeholder="请输入困难类型2" />
        </el-form-item>
        <el-form-item label="人口总数" prop="rkzs">
          <el-input v-model="form.rkzs" placeholder="请输入人口总数" />
        </el-form-item>
        <el-form-item label="收入来源" prop="srly">
          <el-input v-model="form.srly" placeholder="请输入收入来源" />
        </el-form-item>
        <el-form-item label="1城镇，2农村" prop="hjxz">
          <el-input v-model="form.hjxz" placeholder="请输入1城镇，2农村" />
        </el-form-item>
        <el-form-item label="户籍所在地" prop="hjszd">
          <el-input v-model="form.hjszd" placeholder="请输入户籍所在地" />
        </el-form-item>
        <el-form-item label="家庭成员" prop="jtcy">
          <el-input v-model="form.jtcy" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="家庭居住房产" prop="jtjzfqk">
          <el-input v-model="form.jtjzfqk" placeholder="请输入家庭居住房产" />
        </el-form-item>
        <el-form-item label="家庭汽车情况，1自用，2经营用，3无汽车" prop="jtqcqk">
          <el-input v-model="form.jtqcqk" placeholder="请输入家庭汽车情况，1自用，2经营用，3无汽车" />
        </el-form-item>
        <el-form-item label="家庭居住现居住地址" prop="jtxjzdz">
          <el-input v-model="form.jtxjzdz" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="家长电话" prop="jzdh">
          <el-input v-model="form.jzdh" placeholder="请输入家长电话" />
        </el-form-item>
        <el-form-item label="家庭年收入" prop="jtnsr">
          <el-input v-model="form.jtnsr" placeholder="请输入家庭年收入" />
        </el-form-item>
        <el-form-item label="人均年收入，人均年收入=家庭年收入÷家庭人口数" prop="rjnsr">
          <el-input v-model="form.rjnsr" placeholder="请输入人均年收入，人均年收入=家庭年收入÷家庭人口数" />
        </el-form-item>
        <el-form-item label="家庭经济主要收入来源情况,1机关事业单位公职人员,2单位公司合同制职工,3私营业主,4个体工商户,5务工,6务农,7其他收入,8无固定收入,9无收入" prop="jtzysr">
          <el-input v-model="form.jtzysr" placeholder="请输入家庭经济主要收入来源情况,1机关事业单位公职人员,2单位公司合同制职工,3私营业主,4个体工商户,5务工,6务农,7其他收入,8无固定收入,9无收入" />
        </el-form-item>
        <el-form-item label="学生父母丧失劳动能力或劳动能力弱" prop="ssldnl">
          <el-input v-model="form.ssldnl" placeholder="请输入学生父母丧失劳动能力或劳动能力弱" />
        </el-form-item>
        <el-form-item label="其中长期患病或残疾" prop="hbcjr">
          <el-input v-model="form.hbcjr" placeholder="请输入其中长期患病或残疾" />
        </el-form-item>
        <el-form-item label="需赡养丧失劳动能力的共同生活家庭成员" prop="zyssldnl">
          <el-input v-model="form.zyssldnl" placeholder="请输入需赡养丧失劳动能力的共同生活家庭成员" />
        </el-form-item>
        <el-form-item label="突发事件,1家庭遭受疫情,2家庭遭受自然灾害,3家庭遭受突发意外事件,4家庭欠债,5其它情况" prop="tfsj">
          <el-input v-model="form.tfsj" placeholder="请输入突发事件,1家庭遭受疫情,2家庭遭受自然灾害,3家庭遭受突发意外事件,4家庭欠债,5其它情况" />
        </el-form-item>
        <el-form-item label="申请人签名" prop="sqrqm">
          <el-input v-model="form.sqrqm" placeholder="请输入申请人签名" />
        </el-form-item>
        <el-form-item label="申请人签名日期" prop="sqrqmrq">
          <el-input v-model="form.sqrqmrq" placeholder="请输入申请人签名日期" />
        </el-form-item>
        <el-form-item label="班级评议意见，1特别困难" prop="bjpyyj">
          <el-input v-model="form.bjpyyj" placeholder="请输入班级评议意见，1特别困难" />
        </el-form-item>
        <el-form-item label="评议小组组长签名" prop="pyxzzzqm">
          <el-input v-model="form.pyxzzzqm" placeholder="请输入评议小组组长签名" />
        </el-form-item>
        <el-form-item label="评议小组组长签名日期" prop="pyxzzzqmrq">
          <el-input v-model="form.pyxzzzqmrq" placeholder="请输入评议小组组长签名日期" />
        </el-form-item>
        <el-form-item label="辅导员签名" prop="fdyqm">
          <el-input v-model="form.fdyqm" placeholder="请输入辅导员签名" />
        </el-form-item>
        <el-form-item label="辅导员签名日期" prop="fdyqmrq">
          <el-input v-model="form.fdyqmrq" placeholder="请输入辅导员签名日期" />
        </el-form-item>
        <el-form-item label="二级学院领导意见，1特别困难" prop="ejxyldqmyj">
          <el-input v-model="form.ejxyldqmyj" placeholder="请输入二级学院领导意见，1特别困难" />
        </el-form-item>
        <el-form-item label="二级学院领导签名" prop="ejxyldqm">
          <el-input v-model="form.ejxyldqm" placeholder="请输入二级学院领导签名" />
        </el-form-item>
        <el-form-item label="二级学院领导签名日期" prop="ejxyldqmrq">
          <el-input v-model="form.ejxyldqmrq" placeholder="请输入二级学院领导签名日期" />
        </el-form-item>
        <el-form-item label="学校审核意见，1特别困难" prop="xsqmyj">
          <el-input v-model="form.xsqmyj" placeholder="请输入学校审核意见，1特别困难" />
        </el-form-item>
        <el-form-item label="学校签名" prop="xsqm">
          <el-input v-model="form.xsqm" placeholder="请输入学校签名" />
        </el-form-item>
        <el-form-item label="学校签名日期" prop="xsqmrq">
          <el-input v-model="form.xsqmrq" placeholder="请输入学校签名日期" />
        </el-form-item>
        <el-form-item label="创建人ID" prop="createId">
          <el-input v-model="form.createId" placeholder="请输入创建人ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {list} from '@/api/stuYear/index';
import { getDeptName } from '@/api/system/dept';
import { revoke } from '@/api/zxj/poverty/apply';
import { addApply, delApply, listJwc, updateApply } from '@/api/zxj/poverty/applyjl';
export default {
  name: 'Apply',
  data() {
    return {
      yearOptions:[],	
      options: [
        {
          value: '1',
          label: '特别困难',
        },
        {
          value: '2',
          label: '比较困难',
        },
        {
          value: '3',
          label: '一般困难',
        },
        {
          value: '4',
          label: '不困难',
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 困难认定表格数据
      applyList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        step: null,
        xm: null,
        xb: null,
        mz: null,
        sfzhm: null,
        xh: null,
        csny: null,
        knlx: null,
        knlx2: null,
        rkzs: null,
        srly: null,
        hjxz: null,
        hjszd: null,
        jtcy: null,
        jtjzfqk: null,
        jtqcqk: null,
        jtxjzdz: null,
        jzdh: null,
        jtnsr: null,
        rjnsr: null,
        jtzysr: null,
        ssldnl: null,
        hbcjr: null,
        zyssldnl: null,
        tfsj: null,
        sqrqm: null,
        sqrqmrq: null,
        bjpyyj: null,
        pyxzzzqm: null,
        pyxzzzqmrq: null,
        fdyqm: null,
        fdyqmrq: null,
        ejxyldqmyj: null,
        ejxyldqm: null,
        ejxyldqmrq: null,
        xsqmyj: null,
        xsqm: null,
        xsqmrq: null,
        createId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fdyqmrq: [{ required: true, message: '辅导员签名日期不能为空', trigger: 'blur' }],
      },
      deptNameList: [],
    }
  },
  created() {
    this.getList()
    this.getDeptNameList();
    this.listAllYear();
  },
  methods: {
    listAllYear(){
      list().then(res=>{
        this.yearOptions = res.data;
      })
    },
    getDeptNameList() {
      getDeptName().then((res) => {
        this.deptNameList = res.data
      })
    },
    /** 查询困难认定列表 */
    getList() {
      this.loading = true
      listJwc(this.queryParams).then((response) => {
        this.applyList = response.rows
        console.log(this.applyList)
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        step: null,
        xm: null,
        xb: null,
        mz: null,
        sfzhm: null,
        xh: null,
        csny: null,
        knlx: null,
        knlx2: null,
        rkzs: null,
        srly: null,
        hjxz: null,
        hjszd: null,
        jtcy: null,
        jtjzfqk: null,
        jtqcqk: null,
        jtxjzdz: null,
        jzdh: null,
        jtnsr: null,
        rjnsr: null,
        jtzysr: null,
        ssldnl: null,
        hbcjr: null,
        zyssldnl: null,
        tfsj: null,
        sqrqm: null,
        sqrqmrq: null,
        bjpyyj: null,
        pyxzzzqm: null,
        pyxzzzqmrq: null,
        fdyqm: null,
        fdyqmrq: null,
        ejxyldqmyj: null,
        ejxyldqm: null,
        ejxyldqmrq: null,
        xsqmyj: null,
        xsqm: null,
        xsqmrq: null,
        createId: null,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: '/hard/pks/poverty/edit',
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const applylists = this.applyList
      const id = row.id || this.ids
      this.$router.push({
        path: '/hard/pks/poverty/edit',
        query: {
          id: id,
          list: applylists,
          she: 0,
          action: 3,
        },
      })
      // getApply(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改困难认定";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateApply(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addApply(this.form).then((response) => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal
        .confirm('是否确认删除困难认定编号为"' + ids + '"的数据项？')
        .then(function () {
          return delApply(ids)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    handleRevoke(row) {
      this.$modal
        .confirm('是否确认撤回该记录？')
        .then(function () {
          return revoke(row)
        })
        .then((res) => {
          this.getList()
        })
        .catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'knrApproval/srsKnrdapprovalrecord/jwc/export',
        {
          ...this.queryParams,
        },
        `apply_${new Date().getTime()}.xlsx`
      )
    },
  },
}
</script>
